package com.jinsi.utils;

import com.jinsi.pojo.ScUser;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Component
public class Md5Utils {

    /*
     * 加密规则：
     * 1、无视原始密码的强度
     * 2、使用name作为盐值，在原始密码的左右两侧拼接
     * 3、循环加密5次
     */
    public static String getMd5Pwd(ScUser user){
        String pwd = null;
        for (int i = 0; i < 5 ; i++){
            String salt = user.getUserAccount();
            String password = user.getUserPwd();
            pwd = DigestUtils.md5DigestAsHex((salt + password + salt).getBytes()).toUpperCase();
            user.setUserPwd(pwd);
        }
        return pwd;
    }

//    public String getMd5Pwd(String email,String password){
//        String pwd = null;
//        for (int i = 0; i < 5 ; i++){
//            String salt = email;
//            String pass = password;
//            pwd = DigestUtils.md5DigestAsHex((salt + pass + salt).getBytes()).toUpperCase();
//            password = pwd;
//        }
//        return pwd;
//    }
}
